﻿using CP.Utility;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CP.Controllers.GPM;

namespace GPM
{
    public partial class FrmChangePassword : Form
    {
        public FrmChangePassword()
        {
            InitializeComponent();
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.txtOldPwd.Text))
            {
                ExMessageBox.Show("旧密码不能为空", AppSetter.SoftName);
                this.txtOldPwd.Focus();
                return;
            }
            if (string.IsNullOrEmpty(this.txtNewPwd.Text))
            {
                ExMessageBox.Show("新密码不能为空", AppSetter.SoftName);
                this.txtNewPwd.Focus();
                return;
            }
            if (string.IsNullOrEmpty(this.txtConfrimPwd.Text))
            {
                ExMessageBox.Show("确认新密码不能为空", AppSetter.SoftName);
                this.txtConfrimPwd.Focus();
                return;
            }
            if (this.txtNewPwd.Text != txtConfrimPwd.Text)
            {
                ExMessageBox.Show("新密码和确认新密码必须相同", AppSetter.SoftName);
                this.txtConfrimPwd.Focus();
                return;
            }

            UserConfigController config = new UserConfigController();
            try
            {
                config.ChangePassword(AppSetter.CurrentUser.user_id, this.txtOldPwd.Text, this.txtNewPwd.Text);
                ExMessageBox.Show("提示信息：修改密码成功！", AppSetter.SoftName);
                this.Close();
            }
            catch (Exception ex)
            {
                ExMessageBox.Show(ex.Message, AppSetter.SoftName);
            }
        }

        private void txtOldPwd_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                this.btnSave.PerformClick();
            }
        }

    }
}
